﻿using MasterMasterMode.Content.NPCs;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MasterMasterMode.Common.Players
{
    public class RecallBlockPlayer : ModPlayer
    {
        public static bool MagicalHarpActive => CheckForRecallBlock();

        public override void PreUpdate()
        {
            CheckForRecallBlock();
        }
        private static bool CheckForRecallBlock()
        {
            foreach (var npc in Main.npc)
            {
                if (npc.active && npc.type == ModContent.NPCType<MagicalHarp>())
                {
                    if (npc.ModNPC is MagicalHarp)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public override bool CanUseItem(Item item)
        {
            if (IsRecallItem(item) && MagicalHarpActive)
            {
                return false;
            }
            return base.CanUseItem(item);
        }

        private static bool IsRecallItem(Item item)
        {
            return item.type == ItemID.RecallPotion ||
                   item.type == ItemID.TeleportationPotion ||
                   item.type == ItemID.MagicMirror ||
                   item.type == ItemID.IceMirror ||
                   item.type == ItemID.CellPhone ||
                   item.type == ItemID.Shellphone ||
                   item.type == ItemID.ShellphoneHell ||
                   item.type == ItemID.ShellphoneOcean;
        }
    }
}